<%@page import="java.io.PrintWriter"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
    
    <%
    	//request.getSession().removeAttribute("username");
    	String isLogged = (String)request.getSession().getAttribute("username");
    	if(isLogged != null && request.getAttribute("username") == null){
    		//response.sendRedirect("http://titan.cmpe.boun.edu.tr:8085/StoryRoadServer/MainPage.jsp");
    		response.sendRedirect(request.getContextPath()+"/MainPage");
    		//response.sendRedirect("http://titan.cmpe.boun.edu.tr:8085/StoryRoadServer/MainPage");
    	}
    %>

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="shortcut icon" href="bootstrap/assets/ico/favicon.png">

    <title>Welcome to Story Road!</title>

    <!-- Bootstrap core CSS -->
    <link href="bootstrap/dist/css/bootstrap.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="css/loginpage.css" rel="stylesheet">
    <script src="js/gen_validatorv4.js" type="text/javascript"></script>
    
    

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="../../assets/js/html5shiv.js"></script>
      <script src="../../assets/js/respond.min.js"></script>
    <![endif]-->
  </head>

  <body background="img/site_back.png">

    <div class="container">

      <form class="form-signin" name="login_form" action="Login" method="POST">
        <input type="text" name="email" class="form-control" placeholder="Email address" autofocus>
        <input type="password" name="password" class="form-control" placeholder="Password">
        <label class="checkbox">
          <input type="checkbox" value="remember-me" > Remember me
        </label>
        <input type="hidden" name="request_type" value="Web">
        <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
      </form>
      

      <form class="form-signup" action="SignUp" method="POST" id="form-signup">
        <h2 class="form-signin-heading">New to Story Road?</h2>
        <input type="text" class="form-control" name="username" id="signup_field" placeholder="Username">
        <input type="text" class="form-control" name="email" id="signup_field" placeholder="Email address">
        <input type="password" class="form-control" name="password" id="signup_field" placeholder="Password">
        <input type="password" class="form-control" name="confirmPassword" id="signup_field" placeholder="Confirm Password">
        <input type="hidden" name="request_type" value="Web">
        <button class="btn btn-lg btn-primary btn-block" type="submit" id="signup-button">Sign Up</button>
      </form>
        <script  type="text/javascript">
               var frmvalidator = new Validator("form-signup");
               frmvalidator.addValidation("username","req","Please enter a username.");
               frmvalidator.addValidation("email","req","Please enter an e-mail.");
               frmvalidator.addValidation("email","email");
             </script>
      <%
      	if(request.getAttribute("signup_success") != null &&
      		request.getAttribute("signup_success").equals(true)) {
      %>
      <div class="alert alert-success" id="login-alert">
      <center>
      	<Strong>
      	Success!
      	</Strong>
      	You can login with your e-mail and password.
      	</center>
      </div>
      <%
      request.removeAttribute("signup_success");
      	}
      %>
      
      <%
      	if(request.getAttribute("signup_success") != null &&
      		request.getAttribute("signup_success").equals(false)) {
      %>
      <div class="alert alert-danger" id="login-alert">
      <center>
      	<Strong>
		<%if(request.getAttribute("errorCode").equals("Username")){ %>
		Username Already Exists!
		<%} else if(request.getAttribute("errorCode").equals("Email")){ %>
		E-Mail Already Exists!
		<%} else if(request.getAttribute("errorCode").equals("Confirm")){ %>
		Passwords Do Not Match!
		<%} %>
      	</Strong>
      	</center>
      </div>
      <%
      request.removeAttribute("signup_success");
      request.removeAttribute("errorCode");
      	}
      %>
      
      <%
      	if(request.getAttribute("username") != null &&
      		request.getAttribute("username").equals("Fail")) {
      %>
      <div class="alert alert-danger" id="login-alert">
      <center>
	      <Strong>
	      Error!
	      </Strong>
	      	Your attempt to login has failed.
	      </div>
      </center>
      <%
      request.removeAttribute("username");
      	}
      %>

      <%
      	if(request.getAttribute("username") != null &&
      		request.getAttribute("username").equals("Ban")) {
      %>
      <div class="alert alert-danger" id="login-alert">
      <center>
	      <Strong>
	      Error!
	      </Strong>
	      	Your account is banned.
	      </div>
      </center>
      <%
      request.removeAttribute("username");
      	}
      %>

    </div> <!-- /container -->


    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
  </body>
</html>
